<?php 
/*
 * ChromeFrame class, by Olivier St-Laurent
 * version 1.0
 * 
 * This feature, when activate on a website, will automatically use the Chrome frame if the browser is Internet Explorer. 
 * If the Chrome frame is not installed, it will prompt the user to install it with ONE SINGLE CLICK ! 
 * After the installation process, the page will then reload automatically, using the Chrome frame. 
 * No Need For Admin Rights !!! 
 * Works great for IE 6-7-8-9-10, on Windows XP, Vista, 7, 8. 
 * 
 * Usage : 
 *      // Write this code at the beginning of your index page, before any HTML output
 * 
 *      new ChromeFrame(); 
 * 
 *      // All 3 parameters are optional. 
 *      // First parameter is the maximum version of IE on which to show the ChromeFrame. 
 *      //   For example, 9 means that IE 10 and above will not use Chrome frame, but 9 and below will. 
 *      //   By default, it is set to false, which means any version of IE will use the Chrome frame. 
 *      //   You need the Browser class by Olivier St-Laurent for the parameter to work. 
 *      // Second parameter is the temporary page title while installing the Chrome frame. 
 *      //   By default, there is no title. 
 *      // Third parameter is the html text above the install button that will tell the user he needs to install the Chrome Frame. 
 *      //   By default : "You must install Chrome frame to use this website." 
 * 
 */
class ChromeFrame {
    public function __construct($maxIEversion=false, $pageTitle="", $htmlMessage=null) {
        if ($maxIEversion) {
            $maxIEversion = (Browser::getName() == 'msie' && Browser::getVersion() > $maxIEversion);
        }
        if ((isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') != false)) && $maxIEversion == false) { ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="chrome=1" />
        <title><?php echo $pageTitle;?></title>
        <style type="text/css">
            #chromeframe {
                width: 100%;
                height: 600px;
                margin: 0;
                padding: 0;
                border: none;
                position: relative;
                left: 0px;
                top: 0px;
            }
            .chromeFrameInstallDefaultStyle {
                width: 100%;
                height: 100%;
                margin: 0;
                padding: 0;
                border: none;
                position: fixed;
            }
        </style>
    </head>
    <body>
        <!--[if IE]>
            <?php if (empty($htmlMessage)) {?>
            <h3 style="font-family:arial;margin:0;padding:0;margin-bottom:20px;width:100%;height:50px;background-color:#ff0000;color:#000;text-align:center;line-height:50px;vertical-align:middle;">You must install Chrome frame to use this website.</h3>
            <?php } else echo $htmlMessage;?>
            <div id="chromeframe"></div>
            <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js"></script>
            <script type="text/javascript">
             window.attachEvent("onload", function() {
               CFInstall.check({
                 mode: "inline",
                 node: "chromeframe",
                 url: "http://www.google.com/chromeframe/eula.html?user=true"
               });
             });
            </script>
        <![endif]-->
        <![if !IE]>
            <script type="text/javascript">
                window.location.reload(true);
            </script>
        <![endif]>
    </body>
</html>

<?php exit;}
    }
}
